package Handler;

import Control.Control;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;

public class DragAndDrop {

    private Control control;
    private TableTransferHandler tableHandler;
    private TableTransHandlerAux tableHandlerAux;

    public DragAndDrop(JList pAulas, JTable pProfes, JTable pHorario, Control pControl, int tipo) {
        this.control = pControl;
        tableHandler = new TableTransferHandler(pControl);
        tableHandlerAux = new TableTransHandlerAux(pControl);
        this.setHandlerListaAulas(pAulas);
        this.setHandlerTablaProfes(pProfes);
        if (tipo == 1) {
            this.setHandlerTablaHorario(pHorario);
        } else if (tipo == 2) {
            this.setHandlerTablaHorarioAux(pHorario);
        }

    }

    public void setHandlerListaAulas(JList pAulas) {
        pAulas.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        pAulas.setDragEnabled(true);
        pAulas.setTransferHandler(new ListTransferHandler());//indica cual modelo se implementará
        pAulas.setSelectionMode(0); //Selección Única
    }

    public void setHandlerTablaHorario(JTable pHorario) {
        pHorario.getTableHeader().setReorderingAllowed(false);
        pHorario.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        pHorario.setDragEnabled(true);
        pHorario.setTransferHandler(tableHandler);
    }

    public void setHandlerTablaHorarioAux(JTable pHorario) {
        pHorario.getTableHeader().setReorderingAllowed(false);
        pHorario.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        pHorario.setDragEnabled(true);
        pHorario.setTransferHandler(tableHandlerAux);
    }

    public void setHandlerTablaProfes(JTable pProfes) {
        pProfes.getTableHeader().setReorderingAllowed(false);
        pProfes.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        pProfes.setDragEnabled(true);
        pProfes.setTransferHandler(new ExportTransferHandler());
        pProfes.setSelectionMode(0);
    }

}
